import 'package:dio/dio.dart';
import 'package:base_plugin/base_plugin.dart';

class HttpDebitNoteService {
  /// 账单列表
  static Future<Response> debitNoteList({List<String> status}) {
    return BaseConfig.httpBase.get('/api/debit_notes', {
      if (status != null && status.length > 0) ...{
        'status': status?.join(','),
      },
    });
  }

  /// 创建账单
  static Future<Response> createDebitNote({
    int contact_id,
    int bill_id,
    String number,
    String issued_at,
    double subtotal,
    int is_tax_inclusive,
    int tax_id,
    double tax_amount,
    double total,
    String notes,
    String currency_code,
    List attachment_ids,
    List item,
  }) {
    return BaseConfig.httpBase.postJson('/api/debit_notes', {
      "contact_id": contact_id,
      "bill_id": bill_id,
      "number": number,
      "issued_at": issued_at,
      "subtotal": subtotal,
      "is_tax_inclusive": is_tax_inclusive,
      "tax_id": tax_id,
      "tax_amount": tax_amount,
      "total": total,
      "notes": notes,
      'currency_code': currency_code,
      'attachment_ids': attachment_ids ?? [],
      'items': item,
    });
  }

  /// 显示账单
  static Future<Response> showDebitNote(int debitNote) {
    return BaseConfig.httpBase.get('/api/debit_notes/$debitNote', {});
  }

  static Future<Response> debitPayment(int debitID) {
    return BaseConfig.httpBase.get('/api/debit_note/$debitID/payments', {});
  }

  /// 更新账单
  static Future<Response> updateDebitNote(
    int debitNote, {
    int contact_id,
    int bill_id,
    String number,
    String issued_at,
    double subtotal,
    int is_tax_inclusive,
    int tax_id,
    double tax_amount,
    double total,
    String notes,
    String currency_code,
    List attachment_ids,
    List item,
  }) {
    return BaseConfig.httpBase.putJson('/api/debit_notes/$debitNote', {
      "contact_id": contact_id,
      "bill_id": bill_id,
      "number": number,
      "issued_at": issued_at,
      "subtotal": subtotal,
      "is_tax_inclusive": is_tax_inclusive,
      "tax_id": tax_id,
      "tax_amount": tax_amount,
      "total": total,
      "notes": notes,
      'currency_code': currency_code,
      'attachment_ids': attachment_ids ?? [],
      'items': item,
    });
  }

  /// 删除账单
  static Future<Response> deleteDebitNote(int debitNote) {
    return BaseConfig.httpBase.deleteJson('/api/debit_notes/$debitNote', {});
  }

  /// 批量删除账单
  static Future<Response> deleteDebitNotes(List<int> ids) {
    return BaseConfig.httpBase.postJson('/api/debit_notes/batch_delete', {
      'ids': ids,
    });
  }

  /// receiver keep
  static Future<Response> keepCreditNote(int id) {
    return BaseConfig.httpBase.postJson('/api/debit_notes/$id/keep', {});
  }
}
